import { Component ,ChangeDetectorRef} from '@angular/core';
import { Router} from '@angular/router';
import { EventService } from '../../services/QaService';
import { LoginInfoService } from '../../services/login-info.service';
import { BaseUiService } from '../../services/base-ui.service';
import { commService} from '../../services/comm.service';
import { HttpService } from '../../services/http.service';
import { ModalController } from '@ionic/angular';
import {faceRecognition } from '../components/faceRecognition/faceRecognition';
// import wx from 'weixin-jsjs-sdk';
declare var wx: any;
declare var WeixinJSBridge : any;
@Component({
  selector: 'app-tab2',
  templateUrl: 'transaction-page.html',
  styleUrls: ['transaction-page.scss']
})
export class TransactionPage {
  public userInfo:any
  constructor(
    public router:Router,
    public eventService: EventService,
    public LoginInfoService: LoginInfoService,
    public baseUiService: BaseUiService,
    public commService:commService,
    public httpService:HttpService,
    private cd: ChangeDetectorRef,
    public modalController: ModalController,
    ) {
    
    }
 
      toQuestion(index:any){
        this.router.navigate(['/transaction/myquestion'],{queryParams:{
          index:index,
        }})
      }
    


      //人脸识别
      async faceRecognition() {
    
        const modal = await this.modalController.create({
          component: faceRecognition,
          mode: "md",
          cssClass: "conditions",
        });
        await modal.present();
        //监听销毁的事件，此时data存的是模态窗口页面销毁时候的值
        const {data} =await modal.onDidDismiss();
        console.log("模态框事件监听")
        console.log(data)
          return data;
      }

 list=[];
 orderImglist="";
  toOnline(){
    this.userInfo = this.LoginInfoService.getInfo();
    // if(!!!this.userInfo.unitGuid){
    //   this.eventService.eventEmitter.emit('userInfo');    //通知用户中心更新用户信息
    //   return false;
    // }
    // if(!!!this.userInfo.userName){
    //   this.router.navigate(['/mycenter/verified'])
    //   return false;
    // }
    // this.router.navigate(['/transaction/goflow'])
    this.faceRecognition().then(res=>{
      if(res['code']=="200"){
        this.router.navigate(['/transaction/goflow'])
      }
    });
    
  }

  toVideo(){
    this.userInfo = this.LoginInfoService.getInfo();
    if(!!!this.userInfo.unitGuid){
      this.eventService.eventEmitter.emit('userInfo');    //通知用户中心更新用户信息
      return false;
    }
    if(!!!this.userInfo.userName){
      this.router.navigate(['/mycenter/verified'])
      return false;
    }
    // this.router.navigate(['/transaction/video'])
    this.faceRecognition().then(res=>{
      if(res['code']=="200"){
        this.router.navigate(['/transaction/video'])
      }
    });
  
  }

  toSanFang(){
    this.userInfo = this.LoginInfoService.getInfo();
    if(!!!this.userInfo.userName){
      this.router.navigate(['/mycenter/verified'])
      return false;
    } 
    this.router.navigate(['/transaction/sanfanshipin'])
    // this.faceRecognition().then(res=>{
    //   if(res['code']=="200"){
    //     this.router.navigate(['/transaction/sanfanshipin'])
    //   }
    // });
  }

  toCustomer(){
    this.userInfo = this.LoginInfoService.getInfo();
    if(!!!this.userInfo.unitGuid){
      console.log(22222)
      this.eventService.eventEmitter.emit('userInfo');    //通知用户中心更新用户信息
      return false;
    }
    console.log(window['wx'])
    window.location.href="https://wxpay.weixin.qq.com/pub_v2/pay/wap.v2.php"
  //   wx.config({
  //     debug: true, // 开启调试模式,调用的所有api的返回值会在客户端alert出来，若要查看传入的参数，可以在pc端打开，参数信息会通过log打出，仅在pc端时才会打印。
  //     appId: '', // 必填，公众号的唯一标识
  //     timestamp: "", // 必填，生成签名的时间戳
  //     nonceStr: '', // 必填，生成签名的随机串
  //     signature: '',// 必填，签名
  //     jsApiList: [] // 必填，需要使用的JS接口列表 比如我要调用支付接口 那么就是 [chooseWXPay]
  // });
  //    wx.ready(function() {
  //   wx.chooseWXPay({
  //        "appId":"wx5587163ad1875f03",     //公众号名称，由商户传入     
  //        "timeStamp":"1590397753034", //时间戳，自1970年以来的秒数     
  //        "nonceStr":"N309bETyEXVGfi6J", //随机串     
  //        "package":"123123123213",     
  //        "signType":"MD5",  //微信签名方式;    
  //        "paySign":"wx25170918676180e147b710521852475700" ,//微信签名 
  //        success: function () {
  //         // 支付成功后的回调函数
  //         console.log("支付成功");
  //         window.location.href = "/hd/becomevip";
  //     },
  //     cancel: function() {
  //       console.log("支付失败");
  //     }
  //     },
  //     function(res){
  //     if(res.err_msg == "get_brand_wcpay_request:ok" ){
  //     // 使用以上方式判断前端返回,微信团队郑重提示：
  //           //res.err_msg将在用户支付成功后返回ok，但并不保证它绝对可靠。
  //     //do something
  //     } else{
  //     //支付失败处理
  //     }
  //  }); 
  // }.bind(this))
  
    // this.router.navigate(['/transaction/customer'])
  }
}
